<?php
namespace app\admin\controller;
class Crud extends \think\Controller
{
    public function index(){
        
    }
    
    public function Del(){
         $postData = filter_input_array(INPUT_POST);
         $id = $postData["id"];
         $table = $postData["table"];
         $ret = \think\Db::table($table)->delete($id);
         return json_encode($ret);
    }
    
    public function Save(){
        //获取数据 
        $postData = filter_input_array(INPUT_POST);
        $table = $postData["table"];
        //删除table项
        unset($postData['table']);
        
        if (!!trim($postData["id"])) {
              \think\Db::table($table)->update($postData);
              $ret_arr = \think\Db::table($table)->where('id',$postData['id'])->select(); 
              $ret = $ret_arr[0];
              
        }else{
              $id = \think\Db::table($table)->insertGetId($postData);
              $ret = array(
                  'id' => $id
              );
        }
        return json_encode($ret);
    }
    


    public function test(){
       $data = filter_input_array(INPUT_POST);
       
       
       return json_encode($data);
    }
}